package stdio.costa.imoca.api;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import stdio.costa.imoca.notification.sms.SMSResult;
import stdio.costa.imoca.notification.sms.SMSApi;

@Path("/sms")
@Component
@Scope("request")
public class SMSResource {

	@Autowired
	private SMSApi babaiyouSmsSender;

	@Path("/send")
	@POST
	@Produces({ "application/json;qs=1", "application/xml;qs=.5" })
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Transactional
	public SMSResult sendSMS(@QueryParam("access_token") String accessTokenCode,
			@QueryParam("mobile") String mobile,
			@QueryParam("content") String content) throws Exception {
		return babaiyouSmsSender.sendSMS(mobile, content);
	}
}
